<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>微信安全支付</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="__PUBLIC__/Api/css/sm.min.css">
    <link rel="stylesheet" href="__PUBLIC__/Api/css/sm-extend.min.css">
    <link rel="stylesheet" href="__PUBLIC__/Api/css/order.css">
</head>
<body>
<div class="page-group">
    <div class="page page-current pay-details">
        <!--支付详情底部-->
        <div class="order-foot bar bar-standard bar-footer">
            <div class="content-block order-foot-block">
                <div class="row">
                    <div class="col-100">
                    	<a href="#" onclick="callpay()" class="button button-big button-fill button-pay">确定</a>
                    </div>
                </div>
            </div>
        </div>
        <div class="content">
            <!--支付详情头部-->
            <div class="pay-top">
                <p class="unit">费用结算：计价（元）</p>
                <div class="pay-money">
                    <span>{$order['total']}</span>
                </div>
                <p class="time">{$order['service_time']}分钟</p>
            </div>
            <!--支付详情主体-->
            <div class="pay-main">
                <p class="pay-title">配件费用详情</p>
                <div class="pay-head">
                    <div class="row no-gutter">
                        <div class="col-50">服务类别</div>
                        <div class="col-50">配件费用</div>
                    </div>
                </div>
                <div class="pay-body">
                	<notempty name="typeList[1]">
                		<foreach name="typeList[1]" item="detail">
		                    <div class="row no-gutter first-pay">
		                        <div class="col-50">{$detail['name']}</div>
		                        <div class="col-50"><span class="mend-money">{$detail['total_price']}</span></div>
		                    </div>
		                </foreach>
		            </notempty>
                </div>
                <p class="pay-title">服务费用详情</p>
                <div class="pay-head">
                    <div class="row no-gutter">
                        <div class="col-50">服务类别</div>
                        <div class="col-50">配件费用</div>
                    </div>
                </div>
                <div class="pay-body">
                	<notempty name="typeList[2]">
                		<foreach name="typeList[2]" item="detail">
		                    <div class="row no-gutter first-pay">
		                        <div class="col-50">{$detail['name']}</div>
		                        <div class="col-50"><span class="mend-money">{$detail['total_price']}</span></div>
		                    </div>
		                </foreach>
		            </notempty>
                </div>
                <!--超出范围费-->
                <div class="pay-expense">
                    <p class="beyond-expense"><span>协议费</span><span class="beyond-money right">{$typeList['3']['0']['total_price']}元</span></p>
                    <p class="beyond-expense"><span>超出范围费</span><span class="beyond-money right">{$typeList['4']['0']['total_price']}元</span></p>
                    <empty name="coupon">
                    	<p class="coupon" onclick="javascript:window.location.href='{:U('UserCoupon/orderCoupon', 'order_id='.$order['order_id'])}'">
                    		<span>优惠券</span>
                    		<span class="coupon-de right">请选择优惠券</span>
                    	</p>
                    <else/>
	                    <p class="coupon" onclick="javascript:window.location.href='{:U('UserCoupon/orderCoupon', 'order_id='.$order['order_id'].'&coupon_id='.$coupon['coupon_id'])}'">
	                        <span>优惠券</span>
	                        <span class="coupon-de right">
	                        	<if condition="$coupon.minimum eq '0'">
	                        		{$coupon['money']}元
	                        	<else/>
	                        		满{$coupon['minimum']}减{$coupon['money']}元
	                        	</if>
	                        	<i class="icon icon-right"></i>
	                        </span>
	                    </p>
	                </empty>
                </div>
                <div class="pay-title">支付方式</div>
                <div class="pay-method">
                    <div class="list-block item-content">
                        <ul>
                        	<notempty name="totalFee">
	                            <li class="wechat-pay">
	                                <label class="label-checkbox item-content">
	                                    <div class="item-inner">
	                                        <div class="item-title-row">
	                                            <div class="item-title"><i class="wechat-icon"></i>微信支付</div>
	                                        </div>
	                                    </div>
	                                    <input type="radio" name="pay_type" value="1"
	                                    	<notempty name="coupon"> checked</notempty>>
	                                    <div class="item-media"><i class="icon icon-form-checkbox"></i></div>
	                                </label>
	                            </li>
	                        </notempty>
                            <li>
                                <label class="label-checkbox item-content">
                                    <div class="item-inner">
                                        <div class="item-title-row">
                                            <div class="item-title"><i class="cash-icon"></i>现金支付</div>
                                        </div>
                                    </div>
                                    <input type="radio" name="pay_type" value="2">
                                    <div class="item-media"><i class="icon icon-form-checkbox"></i></div>
                                </label>
                            </li>
                        </ul>
                    </div>
                </div>
                <div class="pay-all clearfix">总价 <span class="all-price right">{$totalFee/100}</span></div>
                <input type="hidden" name="order_id" id="order_id" value="{$order['order_id']}"/>
                <input type="hidden" name="coupon_id" id="coupon_id" value="{$coupon['coupon_id']}"/>
            </div>
        </div>
    </div>
</div>

<script type="text/javascript">
    (function(){
        var ThinkPHP = window.Think = {
            "ROOT"   : "__ROOT__", //当前网站地址
            "APP"    : "__APP__", //当前项目地址
            "PUBLIC" : "__PUBLIC__", //项目公共目录地址
            "DEEP"   : "{:C('URL_PATHINFO_DEPR')}", //PATHINFO分割符
            "MODEL"  : ["{:C('URL_MODEL')}", "{:C('URL_CASE_INSENSITIVE')}", "{:C('URL_HTML_SUFFIX')}"],
            "VAR"    : ["{:C('VAR_MODULE')}", "{:C('VAR_CONTROLLER')}", "{:C('VAR_ACTION')}"]
        }
    })();
    
</script>

<script type='text/javascript' src='__PUBLIC__/Api/js/zepto.min.js' charset='utf-8'></script>
<script type='text/javascript' src='__PUBLIC__/Api/js/sm.min.js' charset='utf-8'></script>
<script type='text/javascript' src='__PUBLIC__/Api/js/sm-extend.min.js' charset='utf-8'></script>
<script type="text/javascript" src="__PUBLIC__/Api/js/think.js" charset='utf-8'></script>

<script type="text/javascript">
	//调用微信JS api 支付
	function jsApiCall() {
		WeixinJSBridge.invoke(
						'getBrandWCPayRequest',
						<?php echo $jsApiParameters; ?>,
						function(res) {
							WeixinJSBridge.log(res.err_msg);

							if (res.err_msg == "get_brand_wcpay_request:ok") {
								$.toast('支付完成');
								window.location.href=Think.U('Orders/index', 'type=4');
							} else if (res.err_msg == "get_brand_wcpay_request:cancel") {
								$.toast('已取消支付', 2000);
							}else if (res.err_msg == "get_brand_wcpay_request:fail") {
								$.toast('支付出现问题，请联系客服人员', 3000);
							}
						});
	}
	function callpay() {
		
		var type = $("input[name='pay_type']:checked").val();
		
		if(type == 1){
			if (typeof WeixinJSBridge == "undefined") {
				if (document.addEventListener) {
					document.addEventListener('WeixinJSBridgeReady', jsApiCall,
							false);
				} else if (document.attachEvent) {
					document.attachEvent('WeixinJSBridgeReady', jsApiCall);
					document.attachEvent('onWeixinJSBridgeReady', jsApiCall);
				}
			} else {
				jsApiCall();
			}
		}else if(type == 2){
			
			var orderID = $("#order_id").val();
			var couponID = $("#coupon_id").val();
			var target = Think.U('WeChatApi/payCash');
			$.post(target, {'order_id':orderID, 'coupon_id':couponID}, function(data){
				
				if(data.status == '-201'){
					$.confirm('身份认证已失效，请重新登录', function () {
				        window.location.href = Think.U('Public/login');
				    });
				}else if(data.status == '0'){
					$.confirm('参数错误', function () {
						window.location.href=Think.U('Orders/index');
				    });
				}else if(data.status == '1'){
			        
			        $.alert('您已现金支付，请等待小哥确认', function () {
						window.location.href=Think.U('Orders/index');
				    });
				}
			});
		}else{
			$.toast('请选择支付方式');
		}
	}
</script>

</body>
</html>